﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Macds.Core.Configuration;

namespace Macds.Core.IoC
{
    public class ObjectElement : ConfigurationElement
    {
        [ConfigurationProperty("name", IsRequired = true)]
        public String Name
        {
            get { return (String)this["name"]; }
            set { this["name"] = value; }
        }

        [ConfigurationProperty("assembly", IsRequired = false, DefaultValue = "")]
        public String Assembly
        {
            get { return (String)this["assembly"]; }
            set { this["assembly"] = value; }
        }

        [ConfigurationProperty("class", IsRequired = false, DefaultValue = "")]
        public String Class
        {
            get { return (String)this["class"]; }
            set { this["class"] = value; }
        }

        [ConfigurationProperty("type", IsRequired = false, DefaultValue = "")]
        public String Type
        {
            get { return (String)this["type"]; }
            set { this["type"] = value; }
        }

        [ConfigurationProperty("cacheEnabled", IsRequired = false, DefaultValue = false)]
        public bool CacheEnabled
        {
            get { return (bool)this["cacheEnabled"]; }
            set { this["cacheEnabled"] = value; }
        }

        [ConfigurationProperty("properties", IsRequired = false),
        ConfigurationCollection(typeof(GenericElementCollection<PropertyElement>), AddItemName = "property", ClearItemsName = "clear", RemoveItemName = "remove")]
        public GenericElementCollection<PropertyElement> Properties
        {
            get { return (GenericElementCollection<PropertyElement>)this["properties"]; }
            set { this["properties"] = value; }
        }

        [ConfigurationProperty("parameters", IsRequired = false),
        ConfigurationCollection(typeof(GenericElementCollection<ParameterElement>), AddItemName = "parameter", ClearItemsName = "clear", RemoveItemName = "remove")]
        public GenericElementCollection<ParameterElement> Parameters
        {
            get { return (GenericElementCollection<ParameterElement>)this["parameters"]; }
            set { this["parameters"] = value; }
        }

        public override string ToString()
        {
            return Name.ToString();
        }

        public override bool IsReadOnly()
        {
            return false;
        }
    }
}
